package com.itheima.word;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Scanner;

public class Word {
    public static void main(String[] args) throws IOException {
        //添加文件路径
        File f1=new File("C:\\Users\\Lenovo\\Desktop\\百度分词词库.txt");
        FileInputStream fis=new FileInputStream(f1);
        //字节输入流转换为字符输入流，设置utf-8编码格式以解决乱码问题(默认是GBK)
        InputStreamReader isr=new InputStreamReader(fis,"utf-8");
        //创建字符输入缓冲流对象
        Reader r = new BufferedReader(isr);
        LineNumberReader lnb=new LineNumberReader(r);//从每一行中读取数据
        String line=null;
        ArrayList<String> words = new ArrayList<String>();//定义一个String类型的集合
        while((line=lnb.readLine())!=null)
        {
            words.add(line);
        }
        System.out.println("词汇量:"+words.size());
        Scanner scan =new Scanner(System.in);
        System.out.println("请输入您要查询的词汇:");
        String word = scan.next();
        if(words.contains(word))//利用contains方法判断集合中是否含有该元素
        {
            System.out.println("词库中有该词汇~~~");
        }
        else
        {
            System.out.println("词库中不存在该词汇！！！");
        }
    }

}
